package com.sixi.GeoTransfer;

import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class NeiMengAreaSet {

	public static void main(String[] args) throws IOException {

		File f = new File("./src/main/resources/neimeng_city_info.txt");
		File centreInfo = new File("C:\\Users\\ThinkPad\\Desktop\\内蒙区县.txt");
		
		BufferedReader br = null;
		BufferedReader br2 = null;
		
		br = new BufferedReader(new FileReader(f));
		br2 = new BufferedReader(new FileReader(centreInfo));
		
		//##################################处理中心点区县市
		String temp2;
		
		Map<String, String> areaMap = new HashMap<String, String>();
		
		int areaIndex = 0;
		
		while ((temp2 = br2.readLine()) != null) {
			String[] infoSpli = temp2.split("\\|");
			String phoneNum = "";
			String areaCode = "";
			String cityName = "";
			String cityLng = "";
			String cityLat = "";
			
			
			
			if(infoSpli.length == 2){
				String[] cityInfo = infoSpli[0].split(",");
				if(cityInfo.length == 5){
					phoneNum = cityInfo[0];
					areaCode = cityInfo[1];
					cityName = cityInfo[2];
					cityLng = cityInfo[3];
					cityLat = cityInfo[4];
				}
				String[] areas = infoSpli[1].split(",");
				for(String area : areas){
					String areaInfo = 
						    areaCode + "\t"
						  + phoneNum + "\t"
						  + cityLng+","+cityLat + "\t"
						  + "area" + "\t"
						  + "中国" + "\t"
						  + "内蒙古自治区" + "\t"
						  + cityName + "\t"
						  + area + "\t";
					areaMap.put(area, areaInfo);
					
				}
				
			}
		}
		
		
		//合并经纬度几何形状
		
		 FileOutputStream out = null;
		 out = new FileOutputStream(new File("./src/main/resources/neimeng_city_info.tb"));
		
		String temp;
		
		while ((temp = br.readLine()) != null) {
			String[] polygonInfo = temp.split("\t");
			
			if(polygonInfo.length == 2){
				String areaInfo = areaMap.get(polygonInfo[0]);
				if(areaInfo.split("\t").length==8){
					String[] areaInfoSpli = areaInfo.split("\t");
					String areaCode = areaInfoSpli[0];// areaCode + "\t"
					String phoneNum = areaInfoSpli[1];// phoneNum + "\t"
					String centrePoint = areaInfoSpli[2];// cityLng+","+cityLat + "\t"
					String level = areaInfoSpli[3];// "area" + "\t"
					String country = areaInfoSpli[4];// "中国" + "\t"
					String province = areaInfoSpli[5];// "内蒙古自治区" + "\t"
					String cityName = areaInfoSpli[6];// cityName + "\t"
					String areaName = areaInfoSpli[7];// area + "\t";
					
					String[] centrePointSpli = centrePoint.split(","); //中心点
					
					String polygonPoints = polygonInfo[1]; //多边形
					
					String line = 
							    areaIndex + "\t"
							  + areaCode + "\t"
							  + phoneNum + "\t"
							  + centrePointSpli[0] + areaIndex +","+ centrePointSpli[1] + areaIndex + "\t"
							  + level + "\t"
							  + country + "\t"
							  + province + "\t"
							  + cityName + "\t"
							  + areaName + "\t"
							  + polygonPoints + "\r\n";
					out.write(line.getBytes("utf-8"));
					areaIndex++;
				}

				

			}
			
			

		}
		System.out.println(areaIndex);
		out.flush();
		out.close();
		
	}

}
